#ifndef __GAME_SOLVER_HPP__
#define __GAME_SOLVER_HPP__
/////////////////////////////////////

#include "operationTree.hpp"
#include "navigation.hpp"

class GameSolver
{
public:
    vector<Point2D> empty;
    OperationTree operation;
    Navigator navigation;

    GameSolver() {}

    string solve(_State state)
    {
        
        cout<<"Start to Solve."<<endl;
        if (!operation.findAnswer(state))
            return "Error";
        vector<Point2D> path = operation.translateToPath();
        vector<Point2D> subPath;
        string answer = "";
        // for (int i = 0; i < path.size(); i++)
        //     cout << path[i].x << ',' << path[i].y << "|";
        // cout << endl;
        // cout << "path.size = " << path.size() << endl;
        for (int i = 0; i < path.size() - 1; i++)
        {
            operation.printBoxes(operation.ansBoxList[i]);
            // cout << i << " : " << path[i].x << ',' << path[i].y << endl;
            navigation.init(state.map, (i % 2) ? vector<Point2D>() : (operation.ansBoxList[i]));
            subPath = navigation.navigate(path[i], path[i + 1]);
            answer += navigation.path2cmd(subPath);
        }
        cout<<"Solving done."<<endl;
        return answer;
    }
};

/////////////////////////////////////
#endif